package com.von.relxdemo.service.impl;

import com.von.relxdemo.service.OperateService;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 操作工厂
 */
@Service
public class OperateFactory {

    public static final Map<String, OperateService> map;
    public static final String reg = "[abc]";

    static {
        map = new ConcurrentHashMap<>();
        map.put("a",new AOperateService());
        map.put("b",new BOperateService());
        map.put("c",new COperateService());
    }

    public OperateService getOperateService(String operateType){
        OperateService operateService = map.get(operateType);
        if(operateService == null){
            throw new RuntimeException("没有匹配的运算符");
        }
        return operateService;
    }

    public Boolean checkOperateType(String operateType){
        return operateType.matches(reg);
    }
}
